package com.light.buttons;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.modifier.ColorModifier;
import org.anddev.andengine.entity.modifier.LoopEntityModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import android.content.res.Configuration;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.net.wifi.WifiConfiguration.Status;

import com.huw.debuger.FileIO;
import com.light.buttons.Button.ButtonState;
import com.light.gamecomponents.IGameComponents;
import com.light.mapcomponents.IActionComponents;
import com.light.roller.Direction;
import com.light.roller.Player;
import com.light.roller.ResourceManager;
import com.light.roller.Roller;
import com.light.roller.Stage;

public class ActionButton extends Button
{
	protected Player m_player;
	protected TiledTextureRegion m_tiledTextureRegion;
	public AnimatedSprite m_animatedSprite;
	
	protected float[] m_positionXs = { Roller.CAMERA_WIDTH * 0.955f,
            						   Roller.CAMERA_WIDTH * 0.90f,
                                       Roller.CAMERA_WIDTH * 0.10f,
                                       Roller.CAMERA_WIDTH * 0.045f };
	
	protected float[] m_positionYs = { Roller.CAMERA_HEIGHT * 0.85f,
			   						   Roller.CAMERA_HEIGHT * 0.07f,
			                           Roller.CAMERA_HEIGHT * 0.93f,
			                           Roller.CAMERA_HEIGHT * 0.15f };
	
	protected float[] m_position1Xs = { Roller.CAMERA_WIDTH * 0.93f,
									   Roller.CAMERA_WIDTH * 0.85f,
						               Roller.CAMERA_WIDTH * 0.15f,
						               Roller.CAMERA_WIDTH * 0.07f };

	protected float[] m_position1Ys = { Roller.CAMERA_HEIGHT * 0.8f,
				    				   Roller.CAMERA_HEIGHT * 0.1f,
				    				   Roller.CAMERA_HEIGHT * 0.9f,
				    				   Roller.CAMERA_HEIGHT * 0.2f };
	
	protected float[] m_position2Xs = { Roller.CAMERA_WIDTH * 0.916f,
			   						   Roller.CAMERA_WIDTH * 0.83f,
			   						   Roller.CAMERA_WIDTH * 0.17f,
			   						   Roller.CAMERA_WIDTH * 0.084f };
	
	protected float[] m_position2Ys = { Roller.CAMERA_HEIGHT * 0.73f,
			   						   Roller.CAMERA_HEIGHT * 0.12f,
	                                   Roller.CAMERA_HEIGHT * 0.88f,
	                                   Roller.CAMERA_HEIGHT * 0.27f };
	
	private float m_onScreenPositionX;
	private float m_onScreenPositionY;
    public float getOnScreenPositionX() { return m_onScreenPositionX; }
    public float getOnScreenPositionY() { return m_onScreenPositionY; }
    
    private Stage m_stage;
    private boolean m_blinking = false;
    private boolean m_isForActionComponents = false;
    private Direction m_gravityDirection;

    
	public ActionButton(Roller game, Player player, Stage stage) 
	{
		super(game);
		m_player = player;
		m_state = Button.ButtonState.NOT_CONTROLABLE;
		m_stage = stage;
	}
	
	@Override
	public void hideButton()
	{
		if(m_animatedSprite.getAlpha()==0)return;
		
		LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(1.0f,1,0)));
		if (m_nowModifiler != null)m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
		m_nowModifiler = EntityModifier;
		m_animatedSprite.registerEntityModifier(m_nowModifiler);
		this.setState(ButtonState.NOT_CONTROLABLE);
	}
	
	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		
	}
	@Override
	public void onSensorChanged(SensorEvent event) 
	{
		if (m_animatedSprite != null)
		{
			float[] tempPosX = m_positionXs;
			float[] tempPosY = m_positionYs;
			switch (Button.NOW_SIZE)
			{
			case 0:
				tempPosX = m_positionXs;
				tempPosY = m_positionYs;
				break;
			case 1:
				tempPosX = m_position1Xs;
				tempPosY = m_position1Ys;
				break;
			case 2:
				tempPosX = m_position2Xs;
				tempPosY = m_position2Ys;
				break;
			}
	    	float[] accelerometer_values = event.values.clone();
	    	if (Roller.orientation == Configuration.ORIENTATION_PORTRAIT)
	    	{
		    	if (Math.abs(accelerometer_values[1]) >= Math.abs(accelerometer_values[0]))
		    	{
		    		if (accelerometer_values[1] <= -Roller.GSENSOR_SENSITIVITY && m_direction != Direction.LEFT)
		    		{
		    			int centerX = (int)(tempPosX[2] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[2] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.LEFT;
		    			m_animatedSprite.setRotation(90);
		    		}
		    		else if (accelerometer_values[1] > Roller.GSENSOR_SENSITIVITY && m_direction != Direction.RIGHT)
		    		{
		    			int centerX = (int)(tempPosX[1] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[1] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.RIGHT;
		    			m_animatedSprite.setRotation(-90);
		    		}
		    	}
		    	else
		    	{
		    		if (accelerometer_values[0] <= -Roller.GSENSOR_SENSITIVITY && m_direction != Direction.DOWN)
		    		{
		    			int centerX = (int)(tempPosX[3] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[3] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.DOWN;
		    			m_animatedSprite.setRotation(180);
		    		}
		    		else if (accelerometer_values[0] > Roller.GSENSOR_SENSITIVITY && m_direction != Direction.UP)
		    		{
		    			int centerX = (int)(tempPosX[0] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[0] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.UP;
		    			m_animatedSprite.setRotation(0);
		    		}
		    	}
	    	}
	    	else
	    	{
		    	if (Math.abs(accelerometer_values[1]) >= Math.abs(accelerometer_values[0]))
		    	{
		    		if (accelerometer_values[1] <= -Roller.GSENSOR_SENSITIVITY && m_direction != Direction.DOWN)
		    		{
		    			int centerX = (int)(tempPosX[3] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[3] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.DOWN;
		    			m_animatedSprite.setRotation(180);
		    		}
		    		else if (accelerometer_values[1] > Roller.GSENSOR_SENSITIVITY && m_direction != Direction.UP)
		    		{
		    			int centerX = (int)(tempPosX[0] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[0] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.UP;
		    			m_animatedSprite.setRotation(0);
		    		}
		    	}
		    	else
		    	{
		    		if (accelerometer_values[0] <= -Roller.GSENSOR_SENSITIVITY && m_direction != Direction.RIGHT)
		    		{
		    			int centerX = (int)(tempPosX[1] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[1] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.RIGHT;
		    			m_animatedSprite.setRotation(-90);
		    		}
		    		else if (accelerometer_values[0] > Roller.GSENSOR_SENSITIVITY && m_direction != Direction.LEFT)
		    		{
		    			int centerX = (int)(tempPosX[2] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    	        int centerY =  (int)(tempPosY[2] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    	        m_onScreenPositionX = centerX;
		    	        m_onScreenPositionY = centerY;
		    			m_direction = Direction.LEFT;
		    			m_animatedSprite.setRotation(90);
		    		}
		    	}
	    	}
		}
	}
	@Override
	public void onUpdate(float pSecondsElapsed) {
		Camera tempCamera = Roller.cameraManager.getCamera();
    	setByCameraPosition(tempCamera.getCenterX(), tempCamera.getCenterY());
    	
    	
    	boolean collided = false;
		ArrayList<IGameComponents> temp = m_stage.getGameMap().getEvironmentComponentsList();
		for (int i = 0; i < temp.size(); i++)
		{
			if (temp.get(i) instanceof IActionComponents && 
				((IActionComponents)temp.get(i)).collided(m_player) && 
				m_player.isInAir() && 
				m_player.isAlive() &&
				m_gravityDirection == m_direction)
			{
				changeButtonForAction(true);
				collided = true;
				if (!m_blinking)
				{
					LoopEntityModifier EntityModifier = new LoopEntityModifier(1000, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
					if (m_nowModifiler != null)
						m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
					m_nowModifiler = EntityModifier;
					m_animatedSprite.registerEntityModifier(m_nowModifiler);
					m_blinking = true;
				}
				break;
			}
			
		}
		if (!collided)
			changeButtonForAction(false);
    	
    	//if (m_gravityDirection != m_direction && !m_blinking)
    		changePicture(m_gravityDirection);
    		
	}
	public void changeToSwitchButton()
	{
		if (m_state == ButtonState.MENU_SHOWED)
		{
			if (m_blinking)
			{
				LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(0.5f, m_animatedSprite.getAlpha(), 1)));
				if (m_nowModifiler != null)
					m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
				m_nowModifiler = EntityModifier;
				m_animatedSprite.registerEntityModifier(m_nowModifiler);
				m_blinking = false;
			}
			if (m_animatedSprite.getCurrentTileIndex() != 6)
				m_animatedSprite.setCurrentTileIndex(6);
		}
	}
	@Override
	public void reset() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onLoadEngine() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onLoadResources() {
		ResourceManager.onLoadResources("ActionButton", m_game);
		this.m_tiledTextureRegion = ResourceManager.getTiledTextureRegion("ActionButton");
	}
	@Override
	public void unLoadResources() {
		this.m_textureRegion = null;
		ResourceManager.unLoadResources("ActionButton", m_game);
	}
	@Override
	public void onLoadScene(Scene scene, PhysicsWorld physicsWrold) {
		int centerX = (int)(m_positionXs[0] - this.m_tiledTextureRegion.getTileWidth() / 2);
        int centerY =  (int)(m_positionYs[0] - this.m_tiledTextureRegion.getTileHeight() / 2);
        m_onScreenPositionX = centerX;
        m_onScreenPositionY = centerY;
        m_animatedSprite = new AnimatedSprite(centerX, centerY, this.m_tiledTextureRegion)
		{
			@Override
        	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
        	{
				if (pSceneTouchEvent.isActionDown())
				{
					switch (m_state)
					{
					case PANEL_SHOWED:
						Roller.hintForm.actionButtonCall();
						break;
					case CONTROLABLE:
						ArrayList<IGameComponents> temp = m_stage.getGameMap().getEvironmentComponentsList();
						for (int i = 0; i < temp.size(); i++)
						{
							if (m_isForActionComponents && ((IActionComponents)temp.get(i)).collided(m_player))
							{
								((IActionComponents)temp.get(i)).action(m_player, m_stage);
								m_player.leftClicked = false;
								m_player.rightClicked = false;
							}
						}
						
						if (m_blinking == true)
						{
							LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(1.5f,0,1)));
							if (m_nowModifiler != null)
								m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
							m_nowModifiler = EntityModifier;
							m_animatedSprite.registerEntityModifier(m_nowModifiler);
							((Roller)m_game).changeDirection();
							m_blinking = false;
						}
						break;
					case MENU_SHOWED:
						NOW_SIZE += 1;
						if (NOW_SIZE > 2)
							NOW_SIZE = 0;
						float size = SIZE[NOW_SIZE];
						
						FileIO.SaveButtonSize(m_game, NOW_SIZE);
						m_animatedSprite.setScale(size, size);
						Roller.leftButton.setScale(size);
						Roller.rightButton.setScale(size);
						Roller.jumpButton.setScale(size);
						((Roller)m_game).buttonPositionReset();
					}
				}
				return true;
        	}
		};
		m_animatedSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		m_animatedSprite.setAlpha(0);
		m_animatedSprite.setScale(Button.SIZE[NOW_SIZE]);
		
		scene.registerTouchArea(m_animatedSprite);
		scene.attachChild(m_animatedSprite);
		
	}
	@Override
	public void removeFromScene(Scene scene, PhysicsWorld physicsWorld) {
		scene.detachChild(m_animatedSprite);
		scene.unregisterTouchArea(m_animatedSprite);
	
		m_animatedSprite = null;
		
	}
	@Override
	public void setByCameraPosition(float cameraX, float cameraY) {
		m_animatedSprite.setPosition(cameraX + m_onScreenPositionX - Roller.CAMERA_WIDTH / 2.0f,
				 			         cameraY + m_onScreenPositionY - Roller.CAMERA_HEIGHT / 2.0f);
		
	}
	@Override
	public void rotate(float angle) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void initializeDirection(Direction direction) {
		int centerX;
        int centerY;
        float[] tempPosX = m_positionXs;
		float[] tempPosY = m_positionYs;
		switch (Button.NOW_SIZE)
		{
		case 0:
			tempPosX = m_positionXs;
			tempPosY = m_positionYs;
			break;
		case 1:
			tempPosX = m_position1Xs;
			tempPosY = m_position1Ys;
			break;
		case 2:
			tempPosX = m_position2Xs;
			tempPosY = m_position2Ys;
			break;
		}
		switch (direction)
		{
		case UP:
			centerX = (int)(tempPosX[0] - this.m_tiledTextureRegion.getTileWidth() / 2);
	        centerY =  (int)(tempPosY[0] - this.m_tiledTextureRegion.getTileHeight() / 2);
	        m_onScreenPositionX = centerX;
	        m_onScreenPositionY = centerY;
			m_direction = Direction.UP;
			m_gravityDirection = Direction.UP;
			m_animatedSprite.setRotation(0);
			break;
		case DOWN:
			centerX = (int)(tempPosX[3] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    centerY =  (int)(tempPosY[3] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    m_onScreenPositionX = centerX;
		    m_onScreenPositionY = centerY;
			m_direction = Direction.DOWN;
			m_gravityDirection = Direction.DOWN;
			m_animatedSprite.setRotation(180);
			break;
		case LEFT:
			centerX = (int)(tempPosX[2] - this.m_tiledTextureRegion.getTileWidth() / 2);
		    centerY =  (int)(tempPosY[2] - this.m_tiledTextureRegion.getTileHeight() / 2);
		    m_onScreenPositionX = centerX;
	        m_onScreenPositionY = centerY;
			m_direction = Direction.LEFT;
			m_gravityDirection = Direction.LEFT;
			m_animatedSprite.setRotation(90);
			break;
		case RIGHT:
			centerX = (int)(tempPosX[1] - this.m_tiledTextureRegion.getTileWidth() / 2);
	        centerY =  (int)(tempPosY[1] - this.m_tiledTextureRegion.getTileHeight() / 2);
	        m_onScreenPositionX = centerX;
	        m_onScreenPositionY = centerY;
			m_direction = Direction.RIGHT;
			m_gravityDirection = Direction.RIGHT;
			m_animatedSprite.setRotation(-90);
			break;
		}
		Camera tempCamera = Roller.cameraManager.getCamera();
    	setByCameraPosition(tempCamera.getCenterX(), tempCamera.getCenterY());
	}
	public void changePicture(Direction direction)
	{
		m_gravityDirection = direction;
		if (m_animatedSprite != null && m_state == ButtonState.CONTROLABLE && !m_isForActionComponents)
		{
			switch (direction)
			{
			case RIGHT:
				m_animatedSprite.setCurrentTileIndex(2);
				m_animatedSprite.setRotation(0);
				if (m_direction != Direction.RIGHT && !m_blinking && m_animatedSprite.getAlpha() == 1)
				{
					LoopEntityModifier EntityModifier = new LoopEntityModifier(100000, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
					if (m_nowModifiler != null)
						m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
					m_nowModifiler = EntityModifier;
					m_animatedSprite.registerEntityModifier(m_nowModifiler);
					m_blinking = true;
				}
				else if(m_direction == Direction.RIGHT)
				{
					if (m_blinking)
					{
						LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
						if (m_nowModifiler != null)
							m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
						m_nowModifiler = EntityModifier;
						m_animatedSprite.registerEntityModifier(m_nowModifiler);
					}
					//m_animatedSprite.setCurrentTileIndex(5);
					//m_animatedSprite.setRotation(-90);
					m_blinking = false;
				}
				break;
			case LEFT:
				m_animatedSprite.setCurrentTileIndex(3);
				m_animatedSprite.setRotation(0);
				if (m_direction != Direction.LEFT && !m_blinking && m_animatedSprite.getAlpha() == 1)
				{
					LoopEntityModifier EntityModifier = new LoopEntityModifier(100000, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
					if (m_nowModifiler != null)
						m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
					m_nowModifiler = EntityModifier;
					m_animatedSprite.registerEntityModifier(m_nowModifiler);
					m_blinking = true;
				}
				else if(m_direction == Direction.LEFT)
				{
					if (m_blinking)
					{
						LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
						if (m_nowModifiler != null)
							m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
						m_nowModifiler = EntityModifier;
						m_animatedSprite.registerEntityModifier(m_nowModifiler);
					}
					//m_animatedSprite.setCurrentTileIndex(5);
					//m_animatedSprite.setRotation(90);
					m_blinking = false;
				}
				break;
			case UP:
				m_animatedSprite.setCurrentTileIndex(1);
				m_animatedSprite.setRotation(0);
				if (m_direction != Direction.UP && !m_blinking && m_animatedSprite.getAlpha() == 1)
				{
					LoopEntityModifier EntityModifier = new LoopEntityModifier(100000, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
					if (m_nowModifiler != null)
						m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
					m_nowModifiler = EntityModifier;
					m_animatedSprite.registerEntityModifier(m_nowModifiler);
					m_blinking = true;
				}
				else if(m_direction == Direction.UP)
				{
					if (m_blinking)
					{
						LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
						if (m_nowModifiler != null)
							m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
						m_nowModifiler = EntityModifier;
						m_animatedSprite.registerEntityModifier(m_nowModifiler);
					}
					//m_animatedSprite.setCurrentTileIndex(5);
					//m_animatedSprite.setRotation(0);
					m_blinking = false;
				}
				break;
			case DOWN:
				m_animatedSprite.setCurrentTileIndex(4);
				m_animatedSprite.setRotation(0);
				if (m_direction != Direction.DOWN && !m_blinking && m_animatedSprite.getAlpha() == 1)
				{
					LoopEntityModifier EntityModifier = new LoopEntityModifier(100000, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
					if (m_nowModifiler != null)
						m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
					m_nowModifiler = EntityModifier;
					m_animatedSprite.registerEntityModifier(m_nowModifiler);
					m_blinking = true;
				}
				else if(m_direction == Direction.DOWN)
				{
					if (m_blinking)
					{
						LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(0.5f,0,1)));
						if (m_nowModifiler != null)
							m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
						m_nowModifiler = EntityModifier;
						m_animatedSprite.registerEntityModifier(m_nowModifiler);
					}
					//m_animatedSprite.setCurrentTileIndex(5);
					//m_animatedSprite.setRotation(180);
					m_blinking = false;
				}
				break;
			}
		}

	}
	public void showButton()
	{
		LoopEntityModifier EntityModifier = new LoopEntityModifier(0, new SequenceEntityModifier(new AlphaModifier(1.5f,0,1)));
		if (m_nowModifiler != null)
			m_animatedSprite.unregisterEntityModifier(m_nowModifiler);
		m_nowModifiler = EntityModifier;
		m_animatedSprite.registerEntityModifier(m_nowModifiler);
	}
	
	public void changeButtonForAction(boolean yesOrNo)
	{
		if (yesOrNo && !m_isForActionComponents)
		{
			m_animatedSprite.setCurrentTileIndex(0);
			switch (m_direction)
			{
			case RIGHT:
				m_animatedSprite.setRotation(-90);
				break;
			case LEFT:
				m_animatedSprite.setRotation(90);
				break;
			case UP:
				m_animatedSprite.setRotation(0);
				break;
			case DOWN:
				m_animatedSprite.setRotation(180);
				break;
			}	
			m_isForActionComponents = true;
		}
		else if (!yesOrNo && m_isForActionComponents)
		{
			m_isForActionComponents = false;
			((Roller)m_game).onSensorChanged(Roller.sensorEvent);
		}
	}
}
